package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/15 10:27
 * @apiNote
 */

public class Test00922SortArrayByParityII {
    public static void main(String[] args) {
        int[] nums = {2, 4,5, 3, 5};
        System.out.println(JSON.toJSON(test(nums)));
    }

    public static int[] test(int[] nums){
        int n = nums.length;
        int[] res = new int[n];
        int i = 0;
        for(int num:nums){
            if(num%2==0){
                res[i] = num;
                i += 2;
            }
        }
        i = 1;
        for(int num:nums){
            if(num%2==1){
                res[i] = num;
                i += 2;
            }
        }
        return res;
    }

    public static int[] test1(int[] nums){
        int n = nums.length;
        int[] res= new int[n];
        int left = 0;
        int right = 1;
        for(int num:nums){
            if(num%2 == 0){
                res[left] = num;
                left +=2;
            }else{
                res[right] = num;
                right +=2;
            }
        }
        return res;
    }

}
